package com.yikome.product.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.yikome.product.entity.ProductExt;

public interface ProductExtRepository extends JpaRepository<ProductExt, Long> {

	@Query("select t from ProductExt t where t.yn = 1 and t.sourceId = :sourceId")
	List<ProductExt> findExitsBySourceId(@Param("sourceId")String sourceId);

	@Query("select t from ProductExt t where t.yn = 1 and t.productId = :productId")
	ProductExt findByProductId(@Param("productId")Long productId);

	void deleteByProductId(Long productId);

	@Modifying
	@Query("update ProductExt u set u.categoryId = :newCategoryId where u.categoryId = :oldCategoryId")
	int changeProductCategory(@Param("newCategoryId")Long newCategoryId , @Param("oldCategoryId")Long oldCategoryId);
	
}
